package com.yidu.king.controller;


import com.yidu.king.controller.vo.PersonFeiziVo;
import com.yidu.king.dao.PersonFeiziMapper;
import com.yidu.king.domain.Person;
import com.yidu.king.domain.PersonFeizi;
import com.yidu.king.service.PersonFeiziService;
import com.yidu.king.utils.BaseMessage;
import com.yidu.king.utils.Tools;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * <p>@author yidu-xia</p>
 * <p>@Date: 2021/1/13</p>
 * <p>@Time: 16:33</p>
 * <p>@Description:妃子 </p>
 */
@Controller//控制器
@RequestMapping("/personFeizi")
public class PersonFeiziController {
    @Resource
    PersonFeiziService personFeiziService;

    @RequestMapping("/findAll")
    @ResponseBody
    public Map<String,Object> selectAll(PersonFeiziVo vo){
        List<PersonFeiziVo> list = personFeiziService.selectAll(vo);
        int count = personFeiziService.selectCount(vo);
        return Tools.getLayUiMap(list,count);
    }

    @RequestMapping("/addOrUpdate")
    @ResponseBody
    public BaseMessage addOrUpdate(PersonFeiziVo vo){
        PersonFeizi po = new PersonFeizi();
        BeanUtils.copyProperties(vo,po);
        int rows = 0 ;
        if(vo.getId()==null){
            rows = personFeiziService.insertSelective(po);
        }else {
            rows = personFeiziService.updateByPrimaryKeySelective(po);
        }
        return  rows>0?BaseMessage.succes():BaseMessage.fail();
    }

    @RequestMapping("/deleteAll")
    @ResponseBody
    public BaseMessage deleteAll(String ids){
        int i = personFeiziService.deleteAll(ids);
        return i>0?BaseMessage.succes():BaseMessage.fail();
    }
}